// __PUBLIC__/js/page/admin/goods/addgoods
require(['../../common'], function() {
  require(['goods.addgoods'])
})

define('goods.addgoods', [
    'jquery',
    'css!ke/themes/default/default.css',
    'ke/kindeditor',
    'ke/lang/zh_CN',
    'jqp/validate',
    'css!jqp/nouislider.css',
    'jqp/nouislider',
    'css!ztree/ztree.css',
    'ztree/ztree',
    'jqp/validate'
  ], function($) {
    'use strict';
    var $form = $('#J_form')
    var picHtml = ''
    var sid = $('#J_sid').val()
    var langType = document.documentElement.lang || 'zh-CN'
    var langMap = {
      'zh-CN': 'zh_CN',
      'zh-TW': 'zh_TW',
      'en-US': 'en'
    }
  var editor = KindEditor.editor({
    allowFileManager: true,
    langType: langMap[langType],
    uploadJson: APP + "?app=admin&m=Goods&a=uploadFile"
  })
  KindEditor.loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(KindEditor.VERSION))
 
  KindEditor('#J_selectPic').click(function() {
    editor.loadPlugin('multiimage', function() {
      editor.plugin.multiImageDialog({
        clickFn: function(urlList) {
          KindEditor.each(urlList, function(i, data) {
            var html = ''
            html += '<div  id ="imgs"> '	
            html += '<img  style="margin:5px; opacity:1;width:100px;height:100px" src="' + data.url + '"  />'	
            html += '<input type="hidden" name="imgs[]" value="' + data.url + '" class="input-text">'
            html +=' <a  href="javascript:removePic(\'' + data.url +'\')" onclick="$(this).parent().remove();">删除</a>'
            html += '</div>'		
            $('#J_imageUpload').append(html)
          });
          editor.hideDialog();
        }
      });
    });
  });
  
  $('#J_form').validate({
    classPlace: '.kv',
    errorPlace: '.kv-error',
    errors: {
      goodsname: {
        required: '请填写名称',
      },
    }
  })
})
